import cv2
import socket
import numpy as np
import sys
serverPort = 12000 
buffSize = 65535
#创建服务器套接字
ss = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 
#将端口号12000与该服务器的套接字绑定在一起,即显式地为该套接字分配一个端口号
ss.bind(('', serverPort))
print('The server is ready to receive')
while True:
    #接收
    data,address=ss.recvfrom(buffSize)
    try:
        #格式转换
        data = np.array(bytearray(data)) 
        #解码
        imgdecode=cv2.imdecode(data,1) 
        print('have received one frame')
        #窗口显示
        cv2.imshow('frames',imgdecode) 
        #按下“ESC”退出
        if cv2.waitKey(1)==27: 
             break
    except:
        ss.close()
        cv2.destroyAllWindows()
        sys.exit()
ss.close()
cv2.destroyAllWindows()
